package com.hysf.ioc.pro5_ioc_import;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class AppConfig_3_Test {
	public static void main(String[] args) {
		ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig_3.class);
		
//		Arrays.stream(context.getBeanDefinitionNames()).forEach(System.out::println);
		
		ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory();
		DefaultSingletonBeanRegistry registry = (DefaultSingletonBeanRegistry) beanFactory;
		// 获取所有单例 Bean 的名称
		String[] singletonNames = registry.getSingletonNames();
		
		System.out.println("单例 Bean 数量: " + singletonNames.length);
		for (String name : singletonNames) {
			System.out.println("Bean 名称: " + name + ", 类型: " + registry.getSingleton(name).getClass().getName());
		}
	}
}
